﻿using Caliburn.Micro;
using PublicModule;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace SystemManage.UserManage.ViewModels
{
    public class EditUserViewModel : Screen
    {
        private UserEnt _user;
        public UserEnt EditEnt
        {
            get { return _user; }
            set
            {
                _user = value;
                NotifyOfPropertyChange(nameof(EditEnt));
            }
        }

        public EditUserViewModel()
        {
            EditEnt = new UserEnt();
        }

        public EditUserViewModel(UserEnt ent)
        {
            EditEnt = ent;
        }

        public async void Save()
        {
            EditEnt.Sex = EditEnt.Sex + 1;
            await HttpClientHelper.TryPostAsync<UserEnt>("User/Create", EditEnt);
            this.TryClose(true);
            //Application.Current.Dispatcher.Invoke(new System.Action(()=>{ this.TryClose(); }));
        }

        public void Cancel()
        {
            this.TryClose();
        }
    }
}
